/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 27/01/10
 * Time: 1:28 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Data;
using popLib;
using System.IO;

namespace StartupManager
{
	/// <summary>
	/// Description of Global.
	/// </summary>
	public class Global
	{
		DataTable dt;
		string saveFile = FileLib.getFullPath("data.xml");
		
		private static Global _Global;
		public static Global Instance(){
			if(_Global == null) _Global = new Global();
			return _Global;
		}
		
		public DataTable ApplicationSrc{
			get{ return dt; }
		}
			
		public Global()
		{
			dt = DataLib.initDataTable( "table[ Status, Name, Path, Update, Remove, Start ]" );
			load();
		}
		
		public void save(){
			dt.WriteXml(saveFile);
		}
		
		public void load(){
			if(File.Exists(saveFile))
				dt.ReadXml(saveFile);
		}
		
		public void addItem( string file ){
			if( dt.Select( "Path = '"+file+"'" ).Length == 0 )
			dt.Rows.Add(new object[]{ File.Exists(file),
			                   	Path.GetFileName(file),
			                   	file 
			                   	 });
			
		}
		
		public void addItem( string file, int rowToUpdate ){
			dt.Rows[rowToUpdate][0] = File.Exists(file);
			dt.Rows[rowToUpdate][1] = Path.GetFileName(file);
			dt.Rows[rowToUpdate][2] = file;
		}
	}
}
